<template>
    <div>
        
        <div class="container">
            <h1>创建文章页面</h1><hr>
            <el-form :model="createForm" ref="createForm" label-width="90px">
                <el-form-item label="标题：">
                    <el-input v-model="createForm.title"  style="width:570px;"></el-input>
                </el-form-item>
                <el-form-item label="文章类型：">
                    <el-select v-model="createForm.type" placeholder="请选择文章类型">
                    <el-option label="散文" value="sanwen"></el-option>
                    <el-option label="小说" value="xiaoshuo"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="摘要：">
                    <el-input v-model="createForm.zhaiyao"  style="width:570px;"></el-input>
                </el-form-item>
                <el-form-item label="内容：">
                <textarea v-model="createForm.p" cols="90" rows="10"> </textarea>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">立即创建</el-button>
                    <el-button @click="exit">取消</el-button>
                </el-form-item>
            </el-form>
            
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            createForm:{
                title:'',
                zhaiyao:'',
                p:'',
                type:'',
            }
        }
    },
    methods: {
        onSubmit(){
                    var params = new URLSearchParams();
                    params.append('userno',this.$store.state.userid);
                    params.append('title',this.createForm.title);
                    params.append('zhaiyao',this.createForm.zhaiyao);
                    params.append('leixing',this.createForm.type);
                    params.append('content',this.createForm.p);
            this.$http.post('/news/edit/finish',params).then(res=>{
                window.console.log(res)
                if(res.status!=200)return this.$message('发表失败，请重新发表')
                this.$message.success('发表成功')
                this.shenghe()
                this.$router.push('/myarticle')
            }).catch(err=>{
                this.$message.error('服务器出错，请稍后操作/n'+err)
            })
        },
        //文章全部审核通过
        shenghe(){
            let params = new URLSearchParams
            params.append("userno",this.$store.state.userid)
            this.$http.post('/news/wenzhang/pass/all',params).then(res=>{
                window.console.log(res)
            })
        },
        exit(){
            this.$router.push('/myarticle')
        }
    },
}
</script>
<style scoped>
h1{
    text-align: center;
    padding-top: 10px;
}
.container{
    width: 1000px;
    height:100%;
    background-color: #eee;
    border-radius: 12px;
}
.el-form{
    padding-left: 15%;
}
</style>